import random
import tkinter as tk
import threading
import time

TEXT_LIST = [
    "愿你代码无 bug，上线不翻车！",
    "升职加薪一条龙，年终股票拿不停！",
    "头发倔强不掉队，GitHub 星星天天涨！",
    "需求一改再改，你仍稳如老狗！",
    "写的都被 merge，测的都一次过！",
    "服务器 7×24 不宕机，监控永远一片绿！",
    "愿你每次 git push 都快进，从不 force！",
    "面试必中，Offer 多多，薪资 double！",
    "爱情像缓存，一撞就命中；生活像 CDN，处处加速！",
    "键盘敲出人民币，鼠标点出大别墅！",
    "今天不加班，明天不早起，天天睡到自然醒！",
    "愿你永远 0 警告，0 错误，1 秒编译！",
    "桃花朵朵开，缘分马上来；单身秒脱单，情侣秒结婚！",
    "体重向下，身高向上，余额直线飙升！",
    "愿快乐像死循环，无限嵌套；烦恼像异常，被 catch 就消失！",
    "年年 618、双 11 免单，快递拿到手软！",
    "愿你心中有光，眼里有星辰，卡里有余额！",
    "一行代码千金难换，一个需求万人称赞！",
    "祝你 2025 行大运，2026 更大顺！",
    "愿你走出半生，归来仍是少年；敲尽代码，仍怀热爱！",
]
FONT_SIZE = 22
COLOR_LIST = ["#FF3030", "#00FF7F", "#1E90FF", "#FF69B4", "#FFD700"]
SPEED_X = 3  # 每帧水平移动像素
GAP_Y = 40  # 行间距
MAX_ONSCREEN = 25  # 同时存在的最大弹窗数
LAUNCH_DELTA = 300  # 每隔多少毫秒发射一

root = tk.Tk()
root.withdraw()
SCR_W = root.winfo_screenwidth()
SCR_H = root.winfo_screenheight()
root.destroy()

STOP = False


def new_popup(text, color):
    """创建一个无边框、置顶、透明背景的文字弹窗"""
    win = tk.Toplevel()
    win.overrideredirect(True)  # 去边框
    win.attributes("-topmost", True)  # 置顶
    win.attributes("-transparentcolor", "black")  # 黑色当透明
    win.config(bg="black")

    # 随机行高
    y = random.randint(0, SCR_H // GAP_Y) * GAP_Y
    x = SCR_W
    lbl = tk.Label(
        win, text=text, fg=color, bg="black", font=("微软雅黑", FONT_SIZE, "bold")
    )
    lbl.pack()

    # 先刷一次拿到实际宽高
    win.update_idletasks()
    w = win.winfo_width()
    h = win.winfo_height()

    # 开始坐标
    win.geometry(f"{w}x{h}+{x}+{y}")

    # 飘动线程
    def fly():
        nonlocal x
        while x > -w and not STOP:
            x -= SPEED_X
            win.geometry(f"+{x}+{y}")
            time.sleep(0.015)
        win.destroy()

    threading.Thread(target=fly, daemon=True).start()


def launcher():
    """循环发射弹窗"""
    while not STOP:
        if threading.active_count() - 1 < MAX_ONSCREEN:
            new_popup(random.choice(TEXT_LIST), random.choice(COLOR_LIST))
        time.sleep(LAUNCH_DELTA / 1000)


def kill_all(e=None):
    global STOP
    STOP = True
    time.sleep(0.2)
    tk._default_root.quit()


tk.Tk().withdraw()  # 隐藏根窗口
threading.Thread(target=launcher, daemon=True).start()
tk._default_root.bind("<Escape>", kill_all)
tk._default_root.mainloop()
